import adminsApi from "../../api/admins.js";
import Base from "../Base.js";
import "../../css/index.css";

export default class extends Base {
    handle() {
        this.regBtn.on("click", async e => {
            // 获取值
            const adminName = this.adminNameInput.val();
            const adminPassword = this.adminPasswordInput.val();
            const data = await adminsApi.reg({ adminName, adminPassword });
            data ? layui.layer.msg("注册成功") : layui.layer.msg("账号已存在");
        });
    }
    render() {
        this.el.html(`
        <article class="login-reg-art">
        <h1>猫眼后台管理系统</h1>
        <h2>欢迎注册</h2>
        <div class="tips">
            <p>已有账号?&nbsp;&nbsp;&nbsp;&nbsp;
                <a href="#/login">登录</a>
            </p>
        </div>
        <form class="layui-form" action="#" method="post" style="margin-right:55px;" lay-filter="regForm">
            <div class="layui-form-item">
                <label for="user" class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input type="text" name="adminName" required lay-verify="required" placeholder="请输入用户名"
                        autocomplete="off" class="layui-input" id="user">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="pwd" class="layui-form-label">密&nbsp;&nbsp;&nbsp;&nbsp;码</label>
                <div class="layui-input-block">
                    <input type="password" name="adminPassword" required lay-verify="required" placeholder="请输入密码"
                        autocomplete="off" class="layui-input" id="pwd">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block" style="margin-left: 55px;">
                    <input type="button" value="注册" class="layui-btn" lay-submit lay-filter="reg" id="reg"
                        style="width: 100%;border-radius:19px" ;>
                </div>
            </div>
        </form>
    </article>
        `);
        this.adminNameInput = $("input[name=adminName]");
        this.adminPasswordInput = $("input[name=adminPassword]");
        this.regBtn = $("#reg");
    }
}
